<template>
	<view>
		<view class="uni-list">
			<view class="uni-list-cell" v-for="(item,key) in hideItems" :key="key" >
				<view class=" uni-media-list ">
					<image class="uni-media-list-logo" :src="item.imgUrl"></image>
					<view class="uni-flex uni-row">
							<view class="flex-item">
								{{item.text}}
							</view>
							<view class="flex-item-right">
								<switch :checked ="item.checked" @change="switch1Change" :data-value-id="item.navigateValue" class="color-height"/>
							</view>
					</view>
					
				</view>
			</view>
		</view>

		
		<view class="uni-list">
			<view class="uni-list-cell" @click="goTo(0)">
				<view class="uni-list-cell-navigate uni-navigate-right uni-media-list ">
					<image class="uni-media-list-logo" src="../../static/image/assuation.png"></image>
					<view class="uni-media-list-body" >
						举报
					</view>
				</view>
			</view>
			<view class="uni-list-cell">
				<view class="uni-media-list ">
					合理举报违规用户(涉黄、广告、欺诈信息)，通过后会有积分奖励哦
				</view>
			</view>
			<view class="uni-list-cell" @click="goTo(1)">
				<view class="uni-list-cell-navigate uni-navigate-right uni-media-list ">
					<image class="uni-media-list-logo" src="../../static/image/complain.png"></image>
					<view class="uni-media-list-body" >
						投诉
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations,mapGetters } from 'vuex'
	import {isShiftParty, isExcludeParty, addShiftParty, addExcludeParty, deleteShiftParty, deleteExcludeParty} from '@/api/cms/excludeparty'
	
	import {getBlacks,deleteBlackById, addBlacks } from '@/api/ucenter/index'
	export default {
		data() {
			return {
				hideItems: [{
						text: '不让她（他）看我的帖子',
						imgUrl: '../../static/image/disapprove.png',
						msg: "确定让她（他）看我的帖子",
						navigateValue: 0,
						checked: false,
					},
					{
						text: '我不看她（他）的帖子',
						imgUrl: '../../static/image/eyeclosed.png',
						msg: "确定我需要看她（他）的帖子",
						navigateValue: 1,
						checked: false,
					},
					{
						text: '将她（他）加入黑名单',
						msg: "确定需要将她（他）移出黑名单",
						imgUrl: '../../static/image/my/setting/black.png',
						navigateValue: 2,
						checked: false,
					}
				],
				pageItems: [
					"/pages/security/accusation",
					"/pages/security/complains"
				],
				shiftParty: {},
				excludeParty: {},
				black: {},
				partyId: ""
			};
		},
		onLoad(e) {
			this.partyId = e.fromPartyId;
			this.IsExcludeParty();
			this.IsShiftParty();
			this.IsBlackParty();
		},
		computed: {
			...mapGetters(
				["userId"]
			),
		},
		methods: {
			switch1Change(e) {
				console.log(e.detail.value)
				console.log(JSON.stringify(e));
				console.log(this.partyId);
				let item = this.hideItems[e.mp.currentTarget.dataset.valueId];
				item.checked = e.detail.value
				let content =(item.checked == true ? ("确定"+item.text) : item.msg);
				console.log(JSON.stringify(content));
				let currentData = {
						createdBy: this.userId,
						partyId: this.partyId
					};
				if(e.mp.currentTarget.dataset.valueId == 1) {
					
					this.settingShift(content, item.checked,item.checked?currentData: this.shiftParty)
					
				}
				else if(e.mp.currentTarget.dataset.valueId == 0) {
					if(item.checked == true)
					{
						this.excludeParty = {
							createdBy: this.userId,
							partyId: this.partyId
						}
					}
					this.settingExlcude(content, item.checked,item.checked?currentData:this.excludeParty)
					
				} else if(e.mp.currentTarget.dataset.valueId == 2) {
					if(item.checked == true)
					{
						this.black = {
							createdBy: this.userId,
							partyId: this.partyId
						}
					}
					this.settingBlacks(content, item.checked,item.checked?currentData:this.black)
				}
			},
			getParameters() {
				return {
					page: 1,
					limit: 1,
					partyId: this.partyId,
					createdBy: this.userId,
				}
			},
			IsExcludeParty() {
				isExcludeParty(this.getParameters()).then(response => {
					if(response.status == 200 && response.data.length > 0)
					{
						this.excludeParty =  response.data[0];
						this.hideItems[0].checked = true;
					}
					
				})
			},
			IsShiftParty() {
				isShiftParty(this.getParameters()).then(response => {
					if(response.status == 200 && response.data.length > 0)
					{
						this.shiftParty = response.data[0];
						this.hideItems[1].checked = true;
					}
					
				})
			},
			IsBlackParty() {
				getBlacks(this.getParameters()).then(response => {
					if(response.status == 200 && response.data.length > 0)
					{
						this.shiftParty = response.data[0];
						this.hideItems[2].checked = true;
					}
					
				})
			},
			settingExlcude(content, checked, data) {
				uni.showModal({
					title:"提示",
					content:content,
					success:async function() {
						if(checked == true)
						{
							addExcludeParty(data).then(response => {
								if(response.status == 200 && response.rel == true) {
									uni.showModal({
										title: '成功',
										content: '设置'+content+"成功",
									});
								}
							}).catch(err => {
								uni.showModal({
									title: '失败',
									content: '设置'+content+"不成功",
								});
							})
						}
						else {
							deleteExcludeParty(data.excludeId).then(response => {
								if(response.status == 200 && response.rel == true) {
									uni.showModal({
										title: '成功',
										content: '设置'+content+"成功",
									});
								}
							}).catch(err => {
								uni.showModal({
									title: '失败',
									content: '设置'+content+"不成功",
								});
							})
						}
					}
				})
			},
			settingShift(content, checked, data) {
				uni.showModal({
					title:"提示",
					content:content,
					success:async function() {
						if(checked == true)
						{
							addShiftParty(data).then(response => {
								if(response.status == 200 && response.rel == true) {
									uni.showModal({
										title: '成功',
										content: '设置'+content+"成功",
									});
								}
							}).catch(err => {
								uni.showModal({
									title: '失败',
									content: '设置'+content+"不成功",
								});
							})
						}
						else {
							deleteShiftParty(data.shiftId).then(response => {
								if(response.status == 200 && response.rel == true) {
									uni.showModal({
										title: '成功',
										content: '设置'+content+"成功",
									});
								}
							}).catch(err => {
								uni.showModal({
									title: '失败',
									content: '设置'+content+"不成功",
								});
							})
						}
					}
				})
			},
			settingBlacks(content, checked, data) {
				uni.showModal({
					title:"提示",
					content:content,
					success:async function() {
						if(checked == true)
						{
							addBlacks(data).then(response => {
								if(response.status == 200 && response.rel == true) {
									uni.showModal({
										title: '成功',
										content: '设置'+content+"成功",
									});
								}
							}).catch(err => {
								uni.showModal({
									title: '失败',
									content: '设置'+content+"不成功",
								});
							})
						}
						else {
							deleteBlackById(data.blacklistId).then(response => {
								if(response.status == 200 && response.rel == true) {
									uni.showModal({
										title: '成功',
										content: '设置'+content+"成功",
									});
								}
							}).catch(err => {
								uni.showModal({
									title: '失败',
									content: '设置'+content+"不成功",
								});
							})
						}
					}
				})
			},
			goTo(index) {
				var that = this;
				uni.navigateTo({
					url: that.pageItems[index]
				})
			}
		}
	}
</script>

<style>
	.uni-list {
		width: 710upx !important;
		margin: 20upx;
		border-radius: 15upx;
	}
	
	.color-height {
		height: 50upx !important;
	}
	.uni-media-list-logo {
		width: 50upx !important;
		height: 50upx !important;
	}

	.uni-media-list-body {
		height: 36upx;
		line-height: 36upx;
		font-size: 28upx !important;
		justify-content: space-around;
	}

	.uni-media-list-text-top {
		height: 40upx !important;
		width: 100upx !important;
		overflow: hidden;
	}
	
	.flex-item {
		width: 430upx;
		text-align: left;
	}
	.flex-item-right {
		width: 150upx;
		text-align: right;
	}
</style>
